<%--@elvariable id="user" type="com.genghis.ptas.security.entity.User"--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="X-UA-Compatible" content="IE=edge"/>
    <title>用户编辑</title>
    <meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/>
    <%@include file="../../includes/common.jsp" %>
    <link rel="stylesheet" type="text/css"
          href="<c:url value="/js/common/zTree-v3.5.14/css/zTreeStyle/zTreeStyle.css"/>"/>
    <script src="<c:url value="/js/common/zTree-v3.5.14/js/jquery.ztree.all-3.5.min.js"/>"
            type="text/javascript"></script>
</head>
<body>
<div id="mainContent">
    <form class="form-horizontal">
        <fieldset>
            <legend></legend>
            <div class="control-group">
                <label class="control-label" for="oldPassword">原始密码</label>
                <div class="controls">
                    <input id="oldPassword" name="oldPassword" type="text">
                </div>
            </div>
            <div class="control-group">
                <label class="control-label" for="newPassword">新设密码</label>
                <div class="controls">
                    <input id="newPassword" name="newPassword" type="password">
                </div>
            </div>
            <div class="control-group">
                <label class="control-label" for="newPasswordConfirm">密码确认</label>
                <div class="controls">
                    <input id="newPasswordConfirm" name="newPasswordConfirm" type="password">
                </div>
            </div>
            <div class="control-group">
                <label class="control-label"></label>
                <div class="controls">
                    <input type="button" id="saves" class="btn btn-primary" onclick="save()" value="确认"/>
                    <input type="button" onclick="quit()" class="btn" value="取消"/>
                </div>
            </div>
        </fieldset>
    </form>
</div>
</body>
</html>
<script type="text/javascript">
    var rules = {
        objInfo: {
            oldPassword: {
                checkEmpty: ["oldPassword", "原始密码"],
                ajax: [basePath + "admin/user/checkPassword", {}, {oldPassword: "$('#oldPassword').val().md5()"},
                    backFunc, "text", "POST"]
            },
            newPassword: {
                checkRegExp: ["newPassword", "密码", JCRegExp.letterNum],
                min: ["newPassword", "3", "密码长度"],
                checkEmpty: ["newPassword", "新设密码"]
            },
            newPasswordConfirm: {
                checkEmpty: ["newPasswordConfirm", "密码确认"]
            }
        }
    };

    function backFunc(data, returnObj) {
        returnObj.obj = $('#oldPassword');
        returnObj.errMsg = "原始密码错误！";
        if (data == "true") {
            returnObj.bool = true;
        }
        if (data == "false") {
            returnObj.bool = false;
        }
        return returnObj;
    }

    function save() {
        if (!JC.validate(rules)) return;
        if ($("#newPassword").val() != $("#newPasswordConfirm").val()) {
            $.messager.alert("提示", "两次输入密码不同，请重新输入!");
            return;
        }
        $.ajax({
            url: basePath + "admin/user/changePassword",
            data: {
                id:'${user.id}',
                newPassword: $("#newPassword").val().md5()
            },
            dataType: "json",
            type: "POST",
            success: function () {
                $.messager.alert("提示", "修改密码成功", "", function () {
                    parent.location.href = basePath;
                });
            },
            error: doError
        })
    }

    function quit() {
        parent.location.href = basePath;
    }
</script>